﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using WmsRunStart.Service;

namespace WmsRunStart
{
    internal static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        private static void Main(string[] agr)
        {
            IUpdateChecker checker = new UpdateChecker();
            if (agr.Length == 1 && agr[0].StartsWith(@"update"))
            {
                //如果有参数，则不去检查本地更新
            }
            else
            {
                //如果没有参数，则去检查本地更新
                try
                {
                    checker.UpdateLocalFiles();
                    Process.Start(Application.StartupPath + @"\wmsapp.exe");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            //最终都需要检查服务器更新
            try
            {
                List<UpdateList> list = checker.GetUpdates();
                if (list.Count > 0)
                {
                    checker.DownloadFiles(list);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}